package main

import (
	"fmt"
	"sync"
	"time"
)

var count int = 0
var wg sync.WaitGroup
var mutex sync.Mutex

func test() {
	defer wg.Done()
	mutex.Lock()
	count++
	fmt.Println("count:", count)
	time.Sleep(time.Millisecond * 100)
	mutex.Unlock()
}

func main() {
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go test()
	}
	wg.Wait()
	fmt.Println("main, count: ", count)
}
